<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<span class="timeShow">- -:- -:- -</span>
</body>
<script>
    //js部分
    function timer(countdown_econds) {
        // var countdown_econds = parseInt(1800); //倒计时总秒数量
        var stop_time = localStorage.getItem('stop_time')
        if (stop_time == null || stop_time == undefined || stop_time == 'undefined' || stop_time == 'null') {
            var cur = new Date() // 当前时间
            var cur1 = new Date().getTime()// 当前时间戳
            var end_time = new Date(cur.setSeconds(cur.getSeconds() + 60));
            end_time = end_time.getTime() //结束时间戳
            localStorage.setItem('stop_time',end_time)
        }
        window.setInterval(function () {
            var day = 0,hour = 0,minute = 0,second = 0; //时间默认值
            if (countdown_econds > 0) {
                day = Math.floor(countdown_econds / (60 * 60 * 24));
                hour = Math.floor(countdown_econds / (60 * 60)) - (day * 24);
                minute = Math.floor(countdown_econds / 60) - (day * 24 * 60) - (hour * 60);
                second = Math.floor(countdown_econds) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
            } else { //当时间耗尽，跳回指定页面
                localStorage.setItem('stop_time',null)
                window.location = url;
            }
            if (minute <= 9) minute = '0' + minute;
            if (second <= 9) second = '0' + second;
            $(".timeShow").html('00' + ':' + minute + ':' + second);
            countdown_econds--;
        }, 1000);
    }

    // 数据加载完之后调用
    timer(parseInt(1800));
    if (localStorage.getItem('stop_time') != undefined && !isNaN(localStorage.getItem('stop_time'))) {
        var stop_time = localStorage.getItem('stop_time')
        var now = new Date().getTime();  //当前时间戳
        var countdown_econds = parseInt((stop_time - now) / 1000);
        if (countdown_econds <= 0) {
            localStorage.setItem('stop_time',null)
        } else {
            timer(countdown_econds);
        }
    }
</script>
</html>